<template>
  <el-container class="height100 domainMainContent containerHeight">
    <chunk_item
      ref="chunkItem"
      :headerArr="headerArr"
      :searchItemArr="searchItemArr"
      :tableArr="tableArr"
      :searchChilddata.sync="searchdata"
      @onChunkBtnClick="onChunkBtnClick"
    />
  </el-container>
</template>

<script>
import chunk_item from "@/components/common/chunk_item.vue"
export default {
  components:{
    chunk_item
  },
  created() {
    this.getCustomApps()
     //关于标题的处理
     this.headerArr={iconfont:'icon-icon_dsrw_off',content:this.$t('timedtask')}
     //在这里对传过去的参数赋值
    this.searchItemArr=[{name:'searchword',placeholder:this.$t('name')}]
  },
  mounted() {
    
  },
  provide() {
    return {
      changeMultiSelection: function(){}
    };
  },
  data() {
    return {
      showmode: 'LIST',
      logdata: {},
      searchdata: {
        appdata: [],
        currpage: 1,
        pagelines: 10,
        data:{
          searchword: ''
        }
      },
      multipleSelection: [],
      isLog: 'true',
      content: {},
      tableListConHeight: null,
      headerArr:{},
      searchItemArr:[],
      tableArr:{
        notShowSelection:true,
        tableColumns:[
              {prop:'name',label:this.$t('name')},
              {prop:'creator',label:this.$t('creator')},
              {prop:'period',label:this.$t('period')},
              {prop:'rDate',label:this.$t('runtime')},
              {prop:'runtimes',label:this.$t('runnum')},
              {prop:'startupType',label:this.$t('startup_type')},
              {prop:'state',label:this.$t('state')},
              {
               prop: "state",
               label: this.$t("operating"),
               isBtn: {
                 show: "button",
                 btnArr: [],
              },
             },
          ]
      }
     }
  },
  methods: {
    onChunkBtnClick({name,data}){
        if(name=='tableClick'){
          if(data.rowName=='start'){
            this.startTask(data.rowData)
          }else if(data.rowName=='stop'){
            this.stopTask(data.rowData)
          }
        }
        else if(name=='rowClick'){}
        else{
          this.searchdata={
            ...this.searchdata,
            ...data
          }
          this.searchTableData()
        }
    },
    getCustomApps() {
      this.$api.getCustomAppConfig(
        { domainid: this.$route.query.domainid, data: { name: '' },pagelines:10000 },
        {
          onSucess: (resp) => {
            let arr = resp.data.data.datas
            arr.map((elm) => {
              this.searchdata.appdata.push(elm.id)
            })
            this.searchTableData()
          },
        }
      )
    },
    startTask(row) {
      let data = {
        id: row.id,
        rTime: row.rTime,
        rDate: row.rDate,
        applicationid:row.applicationid,
      }
      this.$api.startTask(data, {
        onSucess: (resp) => {
          if (resp.data.errcode == 0) {
            this.$message({
              showClose: true,
              message: resp.data.data.msg,
              type: 'success',
            })
            this.searchTableData()
          } else {
            this.$message({
              showClose: true,
              message: resp.data.errmsg,
              type: 'error',
            })
          }
        },
      })
    },
    stopTask(row) {
      let data = {
        id: row.id,
        applicationid:row.applicationid
      }
      this.$api.stopTask(data, {
        onSucess: (resp) => {
          if (resp.data.errcode == 0) {
            this.$message({
              showClose: true,
              message: resp.data.data.msg,
              type: 'success',
            })
            this.searchTableData()
          } else {
            this.$message({
              showClose: true,
              message: resp.data.errmsg,
              type: 'error',
            })
          }
        },
      })
    },
    searchTableData() {
      let params = {
        ...this.searchdata,
        searchword: this.searchdata.data.searchword,
        pageNo: this.searchdata.currpage,
        linesPerPage: this.searchdata.pagelines,
      }
      this.$api.getTaskList(params, params.appdata, {
        onSucess: (resp) => {
          this.logdata = resp.data.data
          //这里对table的传值赋值
          this.tableArr={
              ...this.tableArr,
              ...this.logdata,
              type:'timedtask',
            }
          this.$set(this.searchdata,'currpage',this.tableArr.pageNo)
          this.$refs.chunkItem.cancelInterval();
        },
      })
    }
  },
}
</script>